<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="养殖品种" prop="breed">
        <el-select v-model="queryParams.breed" placeholder="请选择养殖品种" @keyup.enter.native="handleQuery">
          <el-option :label="item.breedName" :value="item.breedId" :key="item.breedId" v-for="item in breedList"/>
        </el-select>
      </el-form-item>
      <el-form-item label="产品养殖户" prop="farmers">
        <el-select v-model="queryParams.farmers" placeholder="请选择养殖户" @keyup.enter.native="handleQuery">
          <el-option :label="item.farmersName" :value="item.farmersId" :key="item.farmersId" v-for="item in farmersList"/>
        </el-select>
      </el-form-item>
      <el-form-item label="生产产品" prop="produceProduct">
        <el-select v-model="queryParams.produceProduct" placeholder="请选择产品" @keyup.enter.native="handleQuery">
          <el-option :label="item.productName" :value="item.productId" :key="item.productId" v-for="item in productList"/>
        </el-select>
      </el-form-item>
      <el-form-item label="成品" prop="produceName">
        <el-select v-model="queryParams.produceName" placeholder="请选择成品" @keyup.enter.native="handleQuery">
          <el-option :label="item.produceName" :value="item.produceId" :key="item.produceId" v-for="item in produceList"/>
        </el-select>
      </el-form-item>
      <el-form-item label="生产开始时间" prop="saleReduceTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.produceStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择出库时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="生产结束时间" prop="saleReduceTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.produceEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择出库时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="List">
      <el-table-column label="品种" align="center" prop="breed" />
      <el-table-column label="养殖户" align="center" prop="farmers" />
      <el-table-column label="生产产品" align="center" prop="produceProduct" />
      <el-table-column label="成品" align="center" prop="produceName" />
      <el-table-column label="生产时间" align="center" prop="produceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.produceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数量" align="center" prop="count"/>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { storeIncrease } from "@/api/dy/statistics";
import { queryProduct } from "@/api/dy/product";
import { queryProduce } from "@/api/dy/produce";
import { queryBreed } from "@/api/dy/breed";
import { queryFarmers } from "@/api/dy/farmers";

export default {
  name: "storeincrease",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售单表格数据
      List: [],
      //成品列表
      produceList: [],
      //
      productList: [],
      //
      breedList: [],
      //
      farmersList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        breed: null,
        farmers: null,
        produceName: null,
        produceStartTime: null,
        produceEndTime: null,
        produceProduct: null,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getProduceList();
    this.getProductList();
    this.getBreedList();
    this.getFarmersList();
  },
  methods: {
    /** 查询销售单列表 */
    getList() {
      this.loading = true;
      storeIncrease(this.queryParams).then(response => {
        this.List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询成品列表 */
    getProduceList() {
      queryProduce().then(response => {
        this.produceList = response.data;
      });
    },
    /** 查询产品管理列表 */
    getProductList() {
      queryProduct().then(response => {
        this.productList = response.data;
      });
    },
    /** 查询品种管理列表 */
    getBreedList() {
      queryBreed().then(response => {
        this.breedList = response.data;
      });
    },
    /** 查询养殖户管理列表 */
    getFarmersList() {
      queryFarmers().then(response => {
        this.farmersList = response.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>
